import { Component } from 'react';
import PubSub from 'pubsub-js';
import { withRouter } from 'react-router-dom';

class Search extends Component {
  render() {
    console.log(this.props)
    return (
      <div>
        <input type='text' ref={c => (this.inputRef = c)} />
        <button onClick={this.getData}>发起请求</button>
      </div>
    );
  }
  getData = async () => {
    PubSub.publish('myEvent', { name: 'zjl', time: Date.now() });
    try {
      const response = await fetch('/testapi');
      const data = await response.json();
      console.log('data', data);
    } catch (e) {
      console.log('出错了！', e);
    }
    const {
      inputRef: { value },
    } = this;
    value && this.props.saveUser(value);
  };
}

export default withRouter(Search);
